home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gcctest
/
tests05.zoo
/
tfseek.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-11-07
|
1KB
|
89 lines
#include "ansidecl.h"
#include <stdio.h>
#ifndef SEEK_SET
#define SEEK_SET 0 /* from beginning of file */
#define SEEK_CUR 1 /* from current location */
#define SEEK_END 2 /* from end of file */
#endif
#define TESTFILE "test.dat"
#ifdef sun
#define remove unlink
#endif
int
main()
{
FILE *fp;
int i, j;
#ifdef atarist
_binmode(1);
#endif
/* puts ("\nFile seek test"); */
fp = fopen (TESTFILE, "w");
if (fp == NULL)
{
perror (TESTFILE);
return 1;
}
for (i = 0; i < 256; i++)
putc (i, fp);
if (freopen (TESTFILE, "r", fp) != fp)
{
perror ("Cannot open file for reading");
return 1;
}
for (i = 1; i <= 255; i++)
{
/* printf ("%3d\n", i); */
fseek (fp, (long) -i, SEEK_END);
if ((j = getc (fp)) != 256 - i)
{
printf ("SEEK_END failed %d\n", j);
break;
}
if (fseek (fp, (long) i, SEEK_SET))
{
puts ("Cannot SEEK_SET");
break;
}
if ((j = getc (fp)) != i)
{
printf ("SEEK_SET failed %d\n", j);
break;
}
if (fseek (fp, (long) i, SEEK_SET))
{
puts ("Cannot SEEK_SET");
break;
}
if (fseek (fp, (long) (i >= 128 ? -128 : 128), SEEK_CUR))
{
puts ("Cannot SEEK_CUR");
break;
}
if ((j = getc (fp)) != (i >= 128 ? i - 128 : i + 128))
{
printf ("SEEK_CUR failed %d\n", j);
break;
}
}
fclose (fp);
if(i > 255)
{
remove(TESTFILE);
}
else
{
puts ("Test FAILED!");
}
return (i > 255) ? 0 : 1;
}